package game;

import engine.Keys;
import engine.Mouse;
import math.Maths;
import math.vec3f;

public class Player {
    
    public vec3f pos;
    public vec3f rots;
    public vec3f cosRots;
    public vec3f sinRots;
    private final float speed;
    
    public Player(vec3f _pos, vec3f _rots) {
        pos = new vec3f(_pos);
        rots = new vec3f(_rots);
        cosRots = new vec3f();
        sinRots = new vec3f();
        speed = 3.0f;
    }
    
    public void update(Keys _keys, Mouse _mouse, float timeCycle) {
        if (_mouse.isInsideViewport()) {
            rots.x += _mouse.mouseDY() * 0.0005f;
            rots.y += _mouse.mouseDX() * 0.0005f;
        }
        
        cosRots.x = Maths.cosRad(rots.x);
        cosRots.y = Maths.cosRad(rots.y);
        cosRots.z = Maths.cosRad(rots.z);
        sinRots.x = Maths.sinRad(rots.x);
        sinRots.y = Maths.sinRad(rots.y);
        sinRots.z = Maths.sinRad(rots.z);
        
        float dist = timeCycle * speed;
        if (_keys.isDown(Keys.W)) {
            pos.x += dist * sinRots.y;
            pos.z -= dist * cosRots.y;
        }
        if (_keys.isDown(Keys.S)) {
            pos.x -= dist * sinRots.y;
            pos.z += dist * cosRots.y;
        }
        if (_keys.isDown(Keys.D)) {
            pos.x += dist * cosRots.y;
            pos.z += dist * sinRots.y;
        }
        if (_keys.isDown(Keys.A)) {
            pos.x -= dist * cosRots.y;
            pos.z -= dist * sinRots.y;
        }
        if (_keys.isDown(Keys.R)) {
            pos.y += dist;
        }
        if (_keys.isDown(Keys.F)) {
            pos.y -= dist;
        }
        
        Maths.cap(rots.x, -Maths.PID2, Maths.PID2);
    }
    
}
